package cn.com.guage.dtm.jubian;

/**
 * 实现一个程序 search_matrix(matrix)，参数 matrix 是一个仅包含 0 或 1 两种数字的矩阵，
 * 程序应返回输入矩阵中包含的最大正方形子矩阵（长和宽相等）的区域面积。
 * 例如：
 * 如果 matrix 是[“101011111”，“0000000111”， “1010110111”，“0000110001”]，那么它看起来像下面的矩阵：
 */
import java.util.Scanner;
public class 搜索矩阵 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine(); // 消耗换行符

        int[][] matrix = new int[n][];
        for (int i = 0; i < n; i++) {
            String line = scanner.nextLine().trim();
            int[] row = new int[line.length()];
            for (int j = 0; j < row.length; j++) {
                row[j] = line.charAt(j) - '0';
            }
            matrix[i] = row;
        }

        if (matrix.length == 0 || matrix[0].length == 0) {
            System.out.println(0);
            return;
        }

        int rows = matrix.length;
        int cols = matrix[0].length;
        int[][] dp = new int[rows][cols];
        int maxSide = 0;

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (matrix[i][j] == 1) {
                    if (i == 0 || j == 0) {
                        dp[i][j] = 1;
                    } else {
                        dp[i][j] = Math.min(Math.min(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]) + 1;
                    }
                    maxSide = Math.max(maxSide, dp[i][j]);
                } else {
                    dp[i][j] = 0;
                }
            }
        }

        System.out.println(maxSide * maxSide);
    }
}